import { resolve } from 'path';
const { defineConfig } = require('vite');
import vue from '@vitejs/plugin-vue';

module.exports = defineConfig({
  plugins: [vue()], // to process SFC
  css: {
    preprocessorOptions: {
      sass: {
        additionalData: '@import "./src/styles/variables.scss";',
      },
    },
  },
  resolve: {
    alias: {
      '@': resolve(__dirname, './src'),
      '@enjoy': resolve(__dirname, 'node_modules/@enjoy/mobile'),
    },
  },
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.ts'),
      name: '@enjoy/mobile',
      formats: ['es'], // adding 'umd' requires globals set to every external module
      fileName: (format: any) => `index.${format}.js`,
    },
    rollupOptions: {
      // external modules won't be bundled into your library
      external: ['vue', /primevue\/.+/, 'dayjs', 'echarts'], // not every external has a global
      output: {
        // disable warning on src/index.ts using both default and named export
        exports: 'named',
        // Provide global variables to use in the UMD build
        // for externalized deps (not useful if 'umd' is not in lib.formats)
        globals: {
          vue: 'Vue',
        },
        manualChunks: {
          echarts: ['echarts']
        }
      },
    },
    emptyOutDir: false, // to retain the types folder generated by tsc
  },
});
